<?php

class seoheadAction extends Action
{
    public function index()
    {
        $model = new Model();
        $wherecondition = "t.projectid=p.id and p.employee=e.id and p.type=pt.id and  t.type=11 and t.site=s.id and t.status=0";
        $data = $model->table('ys_project p ,ys_task  t,ys_employee e,ys_projecttype pt,ys_site s')
            ->where($wherecondition)
            ->field('t.*,p.type,e.name as ename,pt.name as ptname,s.domain,s.keyword')
            ->order('t.id')
            ->select();
       $this->list = $data;
        $this->display();
    }

 public function back() 
    {     
		  $id = I('get.id');
		  $model = new Model();
        $where = "t.id=".$id." and t.projectid=p.id and t.site=s.id and p.type=pt.id";
        $data = $model->table('ys_project p ,ys_task  t,ys_projecttype pt,ys_site s')
            ->where($where)
            ->field('t.id as tid,t.name as tname,s.domain,pt.name as ptname')
            ->find();
		 $this->assign('task',$data);
        $this->display();
    }
	public function yuanyin() {
		$task=M('task');
		$data=array();
		$data['id']=I('post.taskid');
		$data['back']=I('post.back');
		$data['status']=-2;
		$count=$task->save($data);
		if($count>0){
			 $this->assign("waitSecond",1);
      $this->assign("jumpUrl",U("seohead/woderenwu" ));
		 $this->success("已退回");
		}else{
		 $this->error("没有退回");
		}
	}
	public function wancheng() {
	$task=M('task');
	$taskid=I('get.id');
	$data=array();
	$data['id']=$taskid;
	$data['status']=2;
	$count=$task->save($data);

		if($count>0){
			 $this->assign("waitSecond",1);
      $this->assign("jumpUrl",U("wangzhanhead/woderenwu" ));
		 $this->success("已完成");
		}else{
		 $this->error("没有完成");
		}

	}
  public function chuangjian()
    {
         $tasktype = M('tasktype');
         $where['parentid']=11;
         $this->list = $tasktype->where($where)->select();

        $this->defaulttime = date("Y-m-d H:i:s", strtotime("+5 days"));
        $id = I('get.id');
		$this->taskid=$id;
        $model = new Model();
        $projectdata = $model->table('ys_site s ,ys_project p,ys_task t')
            ->where(" t.id=" . $id . " and p.id=s.projectid and t.site=s.id")
            ->field('s.*,p.content as pcon')
            ->find();
// echo $model->getLastSql();exit();
        $this->assign('chuangjian', $projectdata);
       
		$this->display();
    }
	 public function addtask()
    {
        $task = D('task');
        $data = $task->create();
        if (!$data) {
            $this->error($data->getError());
        } else {
            $data["status"] = 0;
            if ($data['order'] > 1) $data["status"] = -1;
            $data['nextid'] = $data['order'] + 1;
            $data['preid'] = $data['order'] - 1;
            $data["createtime"] = date("Y-m-d H:i:s");
            $task->add($data);
            $this->assign("waitSecond", 1);
            $this->assign("jumpUrl", U("seohead/woderenwu"));
            $this->success("创建成功");
        }
    }
	
	 public function gongzuoliang()
    {
        $this->display();
    }

  public function  renwulist()
    {  $model = new Model();
	   $name = I('post.sousuo');
	   $where= "t.projectid=p.id and p.type=pt.id and t.site=s.id and t.status=2 and p.employee=e.id ";
        if (IS_POST || !empty($name)) {
              $where=$where." and s.name like '%{$name}%'";
          }
        $data = $model->table('ys_project p ,ys_task t,ys_projecttype pt,ys_employee e,ys_site s')
            ->where($where)
            ->field('t.name as tname,pt.name as ptname,s.*,e.name as ename,t.createtime as ct,t.deadline as dt')
            ->order('t.id')
            ->select();

        //echo $model->getLastSql();exit();
        $this->list = $data;
        $this->display();
    }

 public function woderenwu()
    {
	   $task=M('task');
	  $taskid=I('post.taskid');
	  $data=array();
	  $data['id']=$taskid;
	  $data['taker']="刘宪云" ; //I('session.userid', 0);
	   $data['begintime']=date("Y-m-d H:i:s");
	  $data['status']="1";
	  $task->save($data);

	    header("Content-Type:text/html;charset=utf-8");
        $site = M('task');
        $tasktype = M("tasktype");
        $typdata = $tasktype->field("id,name")->order('id desc')->select();
        /*dump($typdata);*/
        $newtypdata=array();
        foreach ($typdata as $k=>$v) {
            $newtypdata[$v["id"]]=$v;
        }
     /*   dump($newtypdata);
        exit();*/
   $name = I('post.sousuo');
			$where['parentid']=0;
			$where['status']= array('eq',1);;
        if (IS_POST || !empty($name)) {
              $where['name'] = array('like', "%{$name}%");
			  }
      /*     $this->list = $site->where($where)->select();*/
        $data = $site->where($where)->select();
		
        $task = M("task");
        foreach ($data as $k1 => &$v1) {
            $taskcon["parentid"] = $v1["id"];
	        $taskcon['creater']="刘宪云";//I('session.userid', 0);
            $taskdata = $task->where($taskcon)->select();
            foreach ($taskdata as $k => &$v) {
                  $v["type"]=$newtypdata[$v["type"]]["name"];
            }
		
            $v1["task"] = $taskdata;
        }
        $this->list = $data;

        $this->display();
    }
	 public function taskdel(){
	 $task=M('task');
	 $id=$_GET['id'];
	 $res=$task->delete($id);
    if($res>0 ){
	 $this->success("删除成功");
	}else{
	$this->error("删除失败");
	}
    }
	public function pingfen(){
	 $task=M('task');
	 $data=array();
	 $data['id']=I('post.fenid');
	 $data['score']=I('post.fen');
	 if( $data['score']>100){
	 $data['score']=100;
	 }else if($data['score']<0){
	 $data['score']=0;
	 }
	 $task->save($data);
	 $this->redirect('seohead/woderenwu');

	}
 
}